package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Link;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The element FRBRtranslation is the metadata property specifying the source of
 * which this expression is a translation of.
 * 
 * <pre>
 * 	<xsd:element name="FRBRtranslation">
 *  	<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="metaopt">
 * 					<xsd:attributeGroup ref="link"/>
 * 					<xsd:attribute name="fromLanguage" type="language" use="required"/>
 * 					<xsd:attribute name="authoritative" type="yesNoType"/>
 * 					<xsd:attribute name="pivot" type="language"/>
 * 					<xsd:attribute name="by" type="xsd:anyURI" use="required"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 *   	</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * <p>
 * This attribute specifies the human language in which the document the element
 * refers to is expressed. Values are taken from the RFC 4646
 * </p>
 * 
 * @see http://www.ietf.org/rfc/rfc4646.txt
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 * 
 */
public final class FRBRtranslation extends MetaOpt implements Link{

	public static final String ELEMENT = "FRBRtranslation";

	public static final String ATTRIBUTE_FROM_LANGUAGE = "fromLanguage";
	public static final String ATTRIBUTE_AUTHORITATIVE = "authoritative";
	public static final String ATTRIBUTE_PIVOT = "pivot";
	public static final String ATTRIBUTE_BY = "by";
	
	// Mandatory (from Link)
	private String _href;
	
	// Mandatory
	private String _fromLanguage;
	
	// Mandatory
	private String _by;
	
	// Optional
	private String _pivot;

	// Optional
	private String _authoritative;

	/**
	 * @see org.akomantoso.core.data.attribute.Link#getHref()
	 */
	public String getHref() {
		return _href;
	}
	
	/**
	 * @see org.akomantoso.core.data.attribute.Link#setHref(java.lang.String)
	 */
	public void setHref(String href) {
		_href = href;
	}
	
	public String getFromLanguage() {
		return _fromLanguage;
	}
	public void setFromLanguage(String fromLanguage) {
		_fromLanguage = fromLanguage;
	}
	public String getPivot() {
		return _pivot;
	}
	public void setPivot(String pivot) {
		_pivot = pivot;
	}
	public String getBy() {
		return _by;
	}
	public void setBy(String by) {
		_by = by;
	}
	public String getAuthoritative() {
		return _authoritative;
	}
	public void setAuthoritative(String authoritative) {
		_authoritative = authoritative;
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeLink(out, this);
		OutputUtil.writeMandatoryAttribute(out, ATTRIBUTE_FROM_LANGUAGE, _fromLanguage, this);
		OutputUtil.writeMandatoryAttribute(out, ATTRIBUTE_BY, _by, this);
		OutputUtil.writeAttribute(out, ATTRIBUTE_AUTHORITATIVE, _authoritative);
		OutputUtil.writeAttribute(out, ATTRIBUTE_PIVOT, _pivot);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_href = in.readAttribute(Link.ATTRIBUTE);
		_fromLanguage = in.readAttribute(ATTRIBUTE_FROM_LANGUAGE);
		_by = in.readAttribute(ATTRIBUTE_BY);
		_authoritative = in.readAttribute(ATTRIBUTE_AUTHORITATIVE);
		_pivot = in.readAttribute(ATTRIBUTE_PIVOT);
		super.readExternal(in);
	}
	
	
}